package com.v5ba.sms.auto;

import com.v5ba.common.sms.properties.SmsProperties;
import com.v5ba.common.sms.service.SmsService;
import com.v5ba.sms.auto.handler.SmsServiceImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SmsConfiguration {

    @Bean
    @ConfigurationProperties(prefix = "yiren.sms")
    @ConditionalOnProperty(prefix = "yiren.sms", name = {"url", "user-name", "password"})
    public SmsProperties smsProperties(){
        return new SmsProperties();
    }

    @Bean
    @ConditionalOnBean(value = {SmsProperties.class})
    public SmsService smsService() {
        return new SmsServiceImpl(smsProperties());
    }

}
